<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.db.conn"%>
<%@ page import="java.sql.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
<jsp:include flush="true" page="${basePath}/admin/head.jsp"></jsp:include>
<link rel="stylesheet" href="<%=path %>/kindeditor/themes/default/default.css" />
<link rel="stylesheet" href="<%=path %>/kindeditor/plugins/code/prettify.css" />
<script charset="utf-8" src="<%=path %>/kindeditor/kindeditor.js"></script>
<script charset="utf-8" src="<%=path %>/kindeditor/lang/zh_CN.js"></script>
<script charset="utf-8" src="<%=path %>/kindeditor/plugins/code/prettify.js"></script>
<script>
    KindEditor.ready(function(K) {
        var editor1 = K.create('textarea[name="Textarea1"]', {
            cssPath : '<%=path %>/kindeditor/plugins/code/prettify.css',
            uploadJson : '<%=path %>/kindeditor/jsp/upload_json.jsp',
            fileManagerJson : '<%=path %>/kindeditor/jsp/file_manager_json.jsp',
            allowFileManager : true,
            afterCreate : function() {
                var self = this;
                K.ctrl(document, 13, function() {
                    self.sync();
                    document.forms['example'].submit();
                });
                K.ctrl(self.edit.doc, 13, function() {
                    self.sync();
                    document.forms['example'].submit();
                });
            }
        });
        prettyPrint();
    });
</script>

<script src="<%=path %>/admin/js/jquery.js" type="text/javascript"></script>
<script src="<%=path %>/admin/js/formValidator.js" type="text/javascript"></script>  
<script src="<%=path %>/admin/js/formValidatorRegex.js" type="text/javascript"></script>
<link href="<%=path %>/admin/css/validator.css" rel="stylesheet" type="text/css" />


			<script type="text/javascript" src="<%=path%>/admin/js/popup_shuaxin_no.js"></script>
	<script language="javascript">     
		    
	       function up2()
	       {
		        var pop=new Popup({ contentType:1,isReloadOnClose:false,width:400,height:200});
	            pop.setContent("contentUrl","<%=path%>/upfile/upload1.jsp");
	            pop.setContent("title","文件上传");
	            pop.build();
	            pop.show();
	       }
        </script>

<style>
    .ms-panel {
        margin: 0;
        padding: 0;
        background: #fff;
        border-radius: 4px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.12);
    }
    
    .ms-panel-header {
        padding: 20px 24px;
        border-bottom: 1px solid #eee;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    .ms-panel-header h6 {
        margin: 0;
        font-size: 18px;
        font-weight: 500;
        color: #333;
    }
    
    .ms-panel-body {
        padding: 24px;
    }
    
    .add-form-container {
        max-width: 900px;
        margin: 0 auto;
        padding: 20px;
    }
    
    .form-group {
        margin-bottom: 24px;
        display: flex;
        align-items: flex-start;
    }
    
    .form-label {
        width: 120px;
        padding-top: 8px;
        color: #495057;
        font-weight: 500;
        text-align: right;
        padding-right: 16px;
    }
    
    .form-content {
        flex: 1;
    }
    
    .required-mark {
        color: #dc3545;
        margin-right: 4px;
    }
    
    .form-control {
        width: 100%;
        max-width: 300px;
        padding: 8px 12px;
        border: 1px solid #ced4da;
        border-radius: 4px;
        font-size: 14px;
        transition: border-color 0.3s ease;
    }
    
    .form-control:focus {
        border-color: #80bdff;
        outline: none;
        box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);
    }
    
    select.form-control {
        width: 300px;
    }
    
    .editor-container {
        border: 1px solid #ced4da;
        border-radius: 4px;
        overflow: hidden;
    }
    
    .upload-group {
        display: flex;
        align-items: center;
        gap: 12px;
    }
    
    .upload-input {
        flex: 1;
        max-width: 300px;
    }
    
    .upload-btn {
        padding: 8px 16px;
        background: #6c757d;
        color: #fff;
        border: none;
        border-radius: 4px;
        cursor: pointer;
        transition: all 0.3s ease;
    }
    
    .upload-btn:hover {
        background: #5a6268;
        transform: translateY(-1px);
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    
    .button-group {
        display: flex;
        gap: 12px;
        margin-top: 32px;
        padding-left: 136px;
    }
    
    .btn {
        display: inline-flex;
        align-items: center;
        padding: 8px 24px;
        border: none;
        border-radius: 4px;
        font-size: 14px;
        cursor: pointer;
        transition: all 0.3s ease;
    }
    
    .btn-primary {
        background: #28a745;
        color: #fff;
    }
    
    .btn-primary:hover {
        background: #218838;
        transform: translateY(-1px);
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    
    .btn-secondary {
        background: #6c757d;
        color: #fff;
    }
    
    .btn-secondary:hover {
        background: #5a6268;
        transform: translateY(-1px);
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    
    .error-tip {
        color: #dc3545;
        font-size: 12px;
        margin-top: 4px;
    }
</style>

 </head>

 <body class="ms-body ms-aside-left-open ms-primary-theme ms-has-quickbar">
    <!-- Body Content Wrapper -->
    <div class="ms-content-wrapper">
        <div class="row">
            <div class="col-md-12">
                   <div class="ms-panel">
                    <div class="ms-panel-header">
            <h6>添加小说信息</h6>
        </div>
        <div class="ms-panel-body">
                        <div class="add-form-container">
                            <form action="<%=path %>/books_Add" method="post">
                                <div class="form-group">
                                    <label class="form-label">
                                        <span class="required-mark">*</span>小说类别
                                    </label>
                                    <div class="form-content">
                                        <select name="se_caid" id="caidid" class="form-control">
<%
 conn cncaid=new conn();
 ResultSet rscaid=cncaid.query("select  caid,caname from category ");
 while (rscaid.next()) {
%>
<option value="<%= rscaid.getString("caid") %>"><%=rscaid.getString("caname")%></option>
<%} %>
</select>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="form-label">
                                        <span class="required-mark">*</span>小说名称
                                    </label>
                                    <div class="form-content">
                                        <input name="txt_bname" type="text" id="txt_bname" class="form-control" required/>
                                        <div id="txt_bnameTip" class="error-tip"></div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="form-label">
                                        <span class="required-mark">*</span>小说封面
                                    </label>
                                    <div class="form-content">
                                        <div class="upload-group">
                                            <input type="text" name="fujian" id="fujian" class="form-control upload-input" readonly="readonly" />
                                            <button type="button" class="upload-btn" onclick="up2()">上传</button>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="form-label">
                                        <span class="required-mark">*</span>作者
                                    </label>
                                    <div class="form-content">
                                        <input name="txt_author" type="text" id="txt_author" class="form-control" required/>
                                        <div id="txt_authorTip" class="error-tip"></div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="form-label">
                                        <span class="required-mark">*</span>总字数(万)
                                    </label>
                                    <div class="form-content">
                                        <input name="txt_words" type="text" id="txt_words" class="form-control" required/>
                                        <div id="txt_wordsTip" class="error-tip"></div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="form-label">
                                        <span class="required-mark">*</span>价格
                                    </label>
                                    <div class="form-content">
                                        <input name="txt_price" type="text" id="txt_price" class="form-control" required/>
                                        <div id="txt_priceTip" class="error-tip"></div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="form-label">
                                        <span class="required-mark">*</span>小说简介
                                    </label>
                                    <div class="form-content">
                                        <div class="editor-container">
                                            <textarea id="Textarea1" name="Textarea1" cols="100" rows="8" style="width:100%;height:400px;visibility:hidden;"></textarea>
            </div>
        </div>
    </div>

                                <div class="button-group">
                                    <button type="submit" name="btnAdd" class="btn btn-primary" onclick="return jQuery.formValidator.PageIsValid('1');">添加</button>
                                    <button type="button" class="btn btn-secondary" onclick="location.href='<%=path %>/admin/books/books_Manage.jsp'">返回</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

<script language="javascript" type="text/javascript">
    $(document).ready(function() {
        $.formValidator.initConfig({ 
            onError: function(msg) { 
                alert(msg) 
            } 
        });

        // 小说名称验证
        $("#txt_bname").formValidator({ 
            onshow: "请输入小说名称", 
            onfocus: "小说名称不能为空", 
            oncorrect: "合法" 
        }).InputValidator({ 
            min: 1, 
            max: 50,
            onerror: "小说名称长度在1-50个字符之间" 
        });

        // 作者验证
        $("#txt_author").formValidator({ 
            onshow: "请输入作者名称", 
            onfocus: "作者名称不能为空", 
            oncorrect: "合法" 
        }).InputValidator({ 
            min: 1, 
            max: 20,
            onerror: "作者名称长度在1-20个字符之间" 
        });

        // 总字数验证
        $("#txt_words").formValidator({ 
            onshow: "请输入总字数", 
            onfocus: "总字数不能为空", 
            oncorrect: "合法" 
        }).RegexValidator({ 
            regexp: "^[0-9]+(\\.[0-9]{1,2})?$",
            onerror: "请输入有效的数字，最多保留两位小数" 
        });

        // 价格验证
        $("#txt_price").formValidator({ 
            onshow: "请输入价格", 
            onfocus: "价格不能为空", 
            oncorrect: "合法" 
        }).RegexValidator({ 
            regexp: "^[0-9]+(\\.[0-9]{1,2})?$",
            onerror: "请输入有效的价格，最多保留两位小数" 
        });

        // 封面图片验证
        $("#fujian").formValidator({ 
            onshow: "请上传小说封面", 
            onfocus: "封面图片不能为空", 
            oncorrect: "合法" 
        }).InputValidator({ 
            min: 1, 
            onerror: "请上传小说封面" 
        });

        // 小说简介验证
        $("#Textarea1").formValidator({ 
            onshow: "请输入小说简介", 
            onfocus: "小说简介不能为空", 
            oncorrect: "合法" 
        }).InputValidator({ 
            min: 10, 
            max: 1000,
            onerror: "小说简介长度在10-1000个字符之间" 
        });

        // 表单提交前验证
        $("form").submit(function(e) {
            var isValid = true;
            
            // 检查所有必填字段
            $(".required-mark").each(function() {
                var field = $(this).closest('.form-group').find('input, select, textarea');
                if (!field.val()) {
                    isValid = false;
                    field.addClass('error');
                } else {
                    field.removeClass('error');
                }
            });

            // 检查数字字段
            var words = $("#txt_words").val();
            var price = $("#txt_price").val();
            if (isNaN(words) || words <= 0) {
                isValid = false;
                $("#txt_words").addClass('error');
            }
            if (isNaN(price) || price <= 0) {
                isValid = false;
                $("#txt_price").addClass('error');
            }

            if (!isValid) {
                e.preventDefault();
                alert("请检查并填写所有必填字段");
                return false;
            }
        });
    });
</script>

<style>
.error {
    border-color: #dc3545 !important;
}

.error-tip {
    color: #dc3545;
    font-size: 12px;
    margin-top: 4px;
    display: none;
}

.error + .error-tip {
    display: block;
}

.form-control:focus.error {
    box-shadow: 0 0 0 0.2rem rgba(220,53,69,.25);
}
</style>

</body>
</html>









